import { Observer } from 'mobx-vue'
import { Component, Vue } from 'vue-property-decorator'
import { getGridList } from 'src/utils/axios'
import GridAdd from 'src/views/system/grid/components/grid-add/grid-add.vue' 
require('./grid.scss')
@Observer
@Component({
    components:{
        GridAdd
    }
})
export default class ZtGrid extends Vue {
    name:any = '';
     //添加网格弹出层
     isAdd: boolean = false
     // 分页
     page: number = 1
     pageNo: number = 1
     pageSize: number = 10
     count: number = 0//总条数
    tableData:any = [];
    queryForm:any = {
        name: ''
    }
    tableColums:any= [
        {
            title: '#ID',
            key: 'id'
        },
        {
            title: '网格名称',
            key: 'name'
        },
        {
            title: '网格编码',
            key: 'grid_code'
        },
        {
            title: '范围',
            key: 'content'
        },
        {
            title: '所属社区',
            key: 'community_name'
        },
        {
            title: '所属街道',
            key: 'street_name'
        },
        {
            align: 'center',
            title: '操作',
            slot: 'operation'
        }
    ]
    
    mounted() {
       let vm:any = this;
       vm.getList(1);
    }
    // 添加网格
    digAdd() {
      let vm = this
      vm.isAdd = false
      vm.getList(vm.pageNo)
  　}
    async getList(page){
        let vm:any = this;
        let filter:any = {};
        for (let key in vm.queryForm) {
            if (vm.queryForm[key]) {
                filter[key] = (vm.queryForm[key]).trim()
            }
        }
        let params:any = {
            "filter": filter,
            "range": [(page-1)*10, page * 10],
            "sort": []
        }
        
        let out:any = await getGridList(params);
        if (!out.status) {
            if (!out.data.list.length && page > 1) {
                vm.getList(page)
                return
            }
            vm.page = page
            vm.count = out.data.total;
            vm.tableData = out.data.list
            console.log('vm.tableData',vm.tableData)
        }else {
            vm.$Message.error(await vm.$api.xerror(out.status));
        }
    }
     //改变页码
     async changePage(index) {
        this.getList(index)
    }

}
